package com.tc.mapper;

import com.tc.OrderDto.OrderDetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrderMapper {
    //向订单表插入数据
    @Insert("insert into order_detail(order_number, user_id, ipone, address, note, create_time ,state ,shop_name,img,bg_img,price) values (#{orderNumber},#{userId},#{ipone},#{address},#{note},#{createTime},#{state},#{shopName},#{img},#{bgImg},#{price})")
    void addOrder(OrderDetail orderDetail);
    //向关系表中新增菜品与订单的联系
    @Insert("insert into order_food(order_id, food_id, number, category) values(#{param1},#{param2},#{param3},#{param4})")
    void addRelation(Integer orderId, Integer foodId, Integer number, String belongCategory);
    //查找新增的订单id
    @Select("select id from order_detail where order_number=#{uuid}")
    Integer getOrderId(String uuid);
    //获取订单表的主键id
    @Select("select id from order_detail where order_number=#{orderNumber} ")
    Integer selectOrderId(String orderNumber);
    //删除订单表
    @Delete("delete from order_detail where user_id=#{param1} and order_number=#{param2}")
    void deleteOrder(String id, String orderNumber);
    //删除订单与菜品关系表
    @Delete("delete from order_food where order_id=#{orderId}")
    void deleteOrderFoods(Integer orderId);
}
